﻿using System;

namespace CSharpHelpers.Commons
{
    class ExceptionHelper
    {
        public static string GetErrorMessageByException(Exception ex)
        {
            string meg = string.Empty;
            if (ex is System.Runtime.InteropServices.COMException)
            {
                //meg = "缺少組件，請先運行Reg.bat！";
                meg = "Please run the Reg.bat!";
            }
            else if (ex is System.IO.FileNotFoundException)
            {
                //meg = "缺少組件，未安裝水晶報表或没有注册DLL";
                meg = "Please register Crystal Report or other dll.";
            }
            else if (ex is System.Net.Sockets.SocketException)
            {
                //meg = "無法連接到通信服务器;
                meg = "Unable to connect to the TCP Server.";
            }
            else if (ex is NullReferenceException)
            {
                //meg = "找不到相應的數據庫表或數據庫表結構不對";
                meg = "Can't find the corresponding data table or table structure is wrong";
            }
            else if (ex is MySql.Data.MySqlClient.MySqlException)
            {
                //meg = "未連接到數據庫或數據庫出錯";
                meg = "Unable to connect to the database.";
            }
            else if (ex is System.Data.SQLite.SQLiteException)
            {
                //meg = "沒有找到相關權限文件";
                meg = "Couldn't find relevant documents.";
            }
            else
            {
                // 显示全局异常提示
                meg = ex.Message;
            }
            return meg;
        }
    }
}
